﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>jQXB Messaging</title>
    <script type="text/javascript" src="../lib/jquery-1.4.4.js"></script>
    <script type="text/javascript" src="../lib/jQXB.1.1.js"></script>
</head>
<body>
    <h1>Messaging</h1>
    <h2>Change data</h2>
    <div style="background-color: Orange;">
        Original Data
        <input type="text" jqxb-datasource="mydata" jqxb-datamember="Name" />
        <input type="text" jqxb-datasource="mydata" jqxb-datamember="Surname" />
        <input type="text" jqxb-datasource="mydata" jqxb-datamember="Address.Street" />
        <input type="text" jqxb-datasource="mydata" jqxb-datamember="Address.ZipCode" />
    </div>
    <div style="background-color: Silver;">
        Copy 
        <input type="text" jqxb-datasource="mydatacopy" jqxb-datamember="Name" />
        <input type="text" jqxb-datasource="mydatacopy" jqxb-datamember="Surname" />
        <input type="text" jqxb-datasource="mydatacopy" jqxb-datamember="Address.Street" />
        <input type="text" jqxb-datasource="mydatacopy" jqxb-datamember="Address.ZipCode" />
    </div>
    <a id="Anchor Button" href="#" class="dispatchmessage">Click to send message</a>


    <script type="text/javascript">
        var Customer = { 'Name': 'Anthony', 'Surname': 'Murray', 'Address': { 'Street': 'Carnaby Street', 'ZipCode': 'YTSCH'} };
        // Common jQuery entry point

        var MyFunc = {}
        // Define the handler
        MyFunc.displayCopy = function (argument, sender) {
            jQXB.setDataSource('mydatacopy', argument).doBind('mydatacopy');
            alert("[" + sender.attr('id') + "] has sended a message");
        }



        jQuery(document).ready(function () {
            // Initialize the System
            jQXB.initialize();
            jQXB.setDataSource('mydata', Customer).doBind('mydata');
            jQuery('.dispatchmessage').bind('click', function () { jQXBM.fireMessage('DISPLAYOBJ', jQXB.getDataSource('mydata'), jQuery(this)); });
            // Subscribe Message
            jQXBM.subscribeMessage('DISPLAYOBJ', MyFunc.displayCopy);

        });

    </script>
</body>
</html>
